package de.nibian.minecraft.plotRequest;

import java.sql.*;
import java.util.Properties;

public class MySQL {

	//Felder
	private Connection connect = null;
	private Statement statement = null;
	private ResultSet resultSet = null;
	private String url = null;
	private String username = null;
	private String Passwort = null;
	private String Prefix = null;
	private dateienVerarbeiten txtEdit = new dateienVerarbeiten();
	private String plotTabelle;

	public MySQL(){

	}

	public void verbindungHerstellen() {
		Properties sqlconf = txtEdit.propsAuslesen("minecraftplots/config.properties");
		url = "jdbc:mysql://" + sqlconf.getProperty("Host")
				+ ":" + sqlconf.getProperty("Port") + "/"
				+ sqlconf.getProperty("Database");
		username = sqlconf.getProperty("User");	
		Passwort = sqlconf.getProperty("Password");
		Prefix = sqlconf.getProperty("Prefix");
		try {
			connect = DriverManager.getConnection(url, username, Passwort);
			statement = connect.createStatement();
			resultSet = statement.executeQuery("SELECT VERSION()");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public boolean hatUserPlot(String lUsername) throws SQLException{
		ResultSet lrs = null;
		lrs = statement.executeQuery("SELECT * FROM " + plotTabelle 
				+ " WHERE primary_owner = " + lUsername);
		if(lrs == null){
			return false;
		}else{
			return true;
		}
	}
	public Integer freierPlot(){

		return null;
	}
	public void querySenden(String query){
		try {
			statement.executeQuery(query);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public void verbindungBeenden(){
		try {
			connect.close();
			statement.close();
			resultSet.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}